import javax.sound.midi.Soundbank;
import java.security.PublicKey;
import java.util.HashMap;
import java.util.Map;

public class No5 {
    public static void main(String[] args) {
        Solution solution = new Solution();
        System.out.println(solution.longestPalindrome("aba"));
    }



}
class Solution {

    public String longestPalindrome(String s) {
        Map<Integer,String> resMap=new HashMap<>();
        int max=1;
        int charIndex=0;
        int charEnd=0;

        for(int i=0;i<s.length();i++){
            for(int j=i;j<s.length()+1;j++){
                char[] res=s.substring(i,j).toCharArray();
                    if (check(res)&&max<=res.length) {
                        max=res.length;
                        charIndex=i;
                        charEnd=j;
                    }
                }

        }
        return s.substring(charIndex,charEnd);
    }

    public boolean check(char[] res){
        for(int i=0;i<res.length/2;i++){
            if(res[i]!=res[res.length-1-i]){
                return false;
            }
        }
        return true;
    }
}
